package io.openkunlun.javadsl.serialization;

import java.io.IOException;

public interface DaprSerializer {

    DaprSerializer JSON = new JacksonJsonSerializer();
    DaprSerializer JSON_MANIFEST = new JacksonDelegatingSerializer((JacksonSerializer) JSON);

    DaprSerializer CBOR = new JacksonCborSerializer();
    DaprSerializer CBOR_MANIFEST = new JacksonDelegatingSerializer((JacksonSerializer) CBOR);


    /**
     * @param o
     * @return
     * @throws IOException
     */
    byte[] serialize(Object o) throws IOException;

    /**
     * @param o
     * @param type
     * @param <T>
     * @return
     * @throws IOException
     */
    <T> byte[] serialize(Object o, DaprObject<T> type) throws IOException;

    /**
     * @param data
     * @param type
     * @param <T>
     * @return
     * @throws IOException
     */
    <T> T deserialize(byte[] data, Class<T> type) throws IOException;

    /**
     * @param data
     * @param type
     * @param <T>
     * @return
     * @throws IOException
     */
    <T> T deserialize(byte[] data, DaprObject<T> type) throws IOException;
}
